def write_file():
    f = open("haha.txt", "w")
    try:
        a = 10
        b = 4
        rst = a / b
        f.write(str(rst))
    except Exception as e:
        print("出现异常，", e, type(e))
    else:
        print("写出成功")
    finally:
        f.close()
        print("关闭资源")


# print(read_file())
write_file()
